home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7011 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class self destuction???
  5. Date: Wed, 21 Feb 1996 13:56:39 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <312B1687.41C67EA6@intellektik.informatik.th-darmstadt.de>
  8. References: <1996Feb20.152904.13555@alw.nih.gov>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Dean Fuqua wrote:
  16. > I was wondering what the *correct* method of class suicide is.
  17. > For example, while in a member function, a class realizes that
  18. > it is no longer wanted in little computing world and that it should
  19. > kill itself.
  20. > Should it call it own destuctor and that's that or should it do delete(this).
  21. > The delete method seems a bit dangerous to me.
  22.  
  23. Hmm, what do you expect ? -- suicide in the real world seems also
  24. quite dangerous to me ;-)
  25. If you use 'delete this;' the object must have been created via 'new'.
  26. In addition you must not access any (non-static) member after the
  27. object has been destructed. If you can guarantee that this requirements
  28. are not violated there is no problem in using 'delete this'.
  29.  
  30.     Enno
  31.